unicorn = {}

dofile(minetest.get_modpath('unicorn')..'/functions.lua')
dofile(minetest.get_modpath('unicorn')..'/items.lua')
dofile(minetest.get_modpath('unicorn')..'/recipes.lua')

minetest.register_entity('unicorn:unicorn', {
   type = 'unicorn',
   is_mountable = true,
   driver = nil,
   init_tamagochi_timer = true,
   is_pet = true,
   eat_hay = true,
   has_affinity = true,
   breed = true,
   is_wild = false,
   give_orders = true,
   can_be_brushed = true,
   capture_item = "lasso",
   terrain_type = 3,
   skin_colors = {'pink'},
   driver_scale = {x = 1, y = 1},
   driver_attach_at = {x = -0.0325, y = 12.5, z = -0.2},
   driver_eye_offset = {x = 0, y = 14, z = 0},
   pregnant_count = 5,
   physical = true,
   stepheight = 1,
   collide_with_objects = true,
   collisionbox = {-.75,0,-.75,.75,1.5,.75},
   visual = 'mesh',
   mesh = 'unicorn.b3d',
   textures = {'unicorn_pink.png'},
   visual_size = {x=1, y=1},
   timeout = 300,
   max_hp = 100,
   animation = {
      walk = {range={x=10,y=60}, speed=30, loop=true},
      gallop = {range={x=70,y=120}, speed=30, loop=true},
      stand = {range={x=140,y=460}, speed=30, loop=true},
      fly = {range={x=465,y=490}, speed=30, loop=true},
   },
   petz.settings.unicorn_follow,
   drops = {
      {name = 'unicorn:feather', chance = 10, min = 1, max = 4},
      {name = 'unicorn:horn', chance = 3, min = 1, max = 1}
   },
   rotate = 0,
   max_speed = 5,
   jump_height = 2,
   view_range = 10,
   static_save = true,
   springiness= 0,
   buoyancy = 0.5, -- portion of hitbox submerged
   max_speed = 2,
   jump_height = 1.5,
   view_range = 10,
   lung_capacity = 10, -- seconds
   max_hp = 15,
   makes_footstep_sound = true,
   max_height = 20,
   get_staticdata = mobkit.statfunc,
   logic = unicorn.brain,

   on_activate = function(self, staticdata, dtime_s) --on_activate, required
      mobkit.actfunc(self, staticdata, dtime_s)
      petz.set_initial_properties(self, staticdata, dtime_s)
   end,

   on_deactivate = function(self)
      petz.on_deactivate(self)
   end,

   on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
      petz.on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
   end,

   on_rightclick = function(self, clicker)
      petz.on_rightclick(self, clicker)
   end,

   on_step = function(self, dtime)
      mobkit.stepfunc(self, dtime) -- required
      petz.on_step(self, dtime)
   end,

   on_detach_child = function(self, child)
      if self.wagon and not(child:is_player()) then
         local child_ent = child:get_luaentity()
         self.wagon:set_properties({
         visual_size = child_ent.visual_size
         })
         self.wagon = nil
      end
   end,
})

petz:register_egg('unicorn:unicorn', 'Unicorn', 'unicorn_spawn_egg.png', true)
